package com.hex.ds.hdtp.core.inf.script.transfer.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.script.transfer.mapper.IScriptConvertOptLogMapper;
import com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertOptLogPo;
import com.hex.ds.hdtp.core.inf.script.transfer.repository.IScriptConvertOptLogRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptConvertOptLogRepository implements IScriptConvertOptLogRepository {

    private final IScriptConvertOptLogMapper scriptConvertOptLogMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /**
     * @Method queryById
     * @Param [pkId]
     * @Return com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertListHisPo
     * @Description 根据主键查询
     * @Author Guo jiajun
     * @Date 2023/5/15 16:08
     * @Version V1.0
     */
    @Override
    public ScriptConvertOptLogPo queryById(String pkId) {
        return scriptConvertOptLogMapper.selectById(pkId);
    }

    /**
     * @Method add
     * @Param [scriptConvertListHisPo]
     * @Return java.lang.Integer
     * @Description 新增
     * @Author Guo jiajun
     * @Date 2023/5/15 16:09
     * @Version V1.0
     */
    @Override
    public Integer add(ScriptConvertOptLogPo scriptConvertOptLogPo) {
        return scriptConvertOptLogMapper.insert(scriptConvertOptLogPo);
    }

    /**
     * @Method modifyById
     * @Param [scriptConvertListHisPo]
     * @Return java.lang.Integer
     * @Description 根据主键更新
     * @Author Guo jiajun
     * @Date 2023/5/15 16:09
     * @Version V1.0
     */
    @Override
    public Integer modifyById(ScriptConvertOptLogPo scriptConvertOptLogPo) {
        return scriptConvertOptLogMapper.updateById(scriptConvertOptLogPo);
    }

    /**
     * @Method removeById
     * @Param [pkId]
     * @Return java.lang.Integer
     * @Description 根据主键删除
     * @Author Guo jiajun
     * @Date 2023/5/15 16:09
     * @Version V1.0
     */
    @Override
    public Integer removeById(String pkId) {
        return scriptConvertOptLogMapper.deleteById(pkId);
    }

    /**
     * @Method queryListByPage
     * @Param [scriptConvertListHisPo, page]
     * @Return com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertListHisPo>
     * @Description 分页查询
     * @Author Guo jiajun
     * @Date 2023/5/15 16:09
     * @Version V1.0
     */
    @Override
    public Page<ScriptConvertOptLogPo> queryListByPage(ScriptConvertOptLogPo scriptConvertOptLogPo, Page page) {
        final IPage tmpPageResult = scriptConvertOptLogMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , scriptConvertOptLogPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    @Override
    public List<ScriptConvertOptLogPo> queryByScriptConvertListId(String convertListId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("script_convert_list_id", convertListId);
        return scriptConvertOptLogMapper.selectList(queryWrapper);
    }


}
